<template>
  <t-loading :loading="loading">
    <div class="parent-box">
      <DydEditor v-model="Description" :Descriptions="Description" v-if="!loading"></DydEditor>
      <t-row>
        <t-col :span="12">
          <div class="hw-flex-style-c-a-r">
            <t-button size="large" @click="save" :loading="loadingBtn"> 保存 </t-button>
          </div>
        </t-col>
      </t-row>
    </div>
  </t-loading>
</template>

<script setup lang="ts">
// @ts-nocheck
import { MessagePlugin } from 'tdesign-vue-next';
import { copyrightSave, copyrightInfo } from '@/api/templates/templates';
import { ref, reactive } from 'vue';
import DydEditor from '@/components/RichText/Editor.vue';

const Description = ref('');
const loading = ref(true);
const loadingBtn = ref(false);
const init = async () => {
  try {
    let { data } = await copyrightInfo(localStorage.getItem('projectId'));
    if (data) {
      Description.value = data;
    }
    loading.value = false;
  } catch {
    loading.value = false;
  }
};
const save = async () => {
  loadingBtn.value = true;
  let { statusCode } = await copyrightSave({
    value: localStorage.getItem('projectId'),
    text: Description.value,
  });
  if (statusCode == 200) {
    MessagePlugin.success('保存成功');
  }
  loadingBtn.value = false;
};
init();
</script>

<style lang="less" scoped>
.parent-box {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: calc(100vh - 400px);
  padding: 0 12px;
  :deep(.tinymce-boxz) {
    height: 90%;
  }
  :deep(.tox-tinymce) {
    height: 100% !important;
  }
}
</style>
